#! /usr/bin/env python

import waf_graphics, waf_dynamo, waflib
from waf_dynamo import apidoc_extract_task, dmsdk_add_files

def options(opt):
    pass

def configure(cont):
    pass

def build(bld):
    sources = bld.path.ant_glob('render/*.cpp') + bld.path.ant_glob('render/font/*.cpp') + bld.path.parent.ant_glob('proto/render/*.proto')
    if 'web' in bld.env.PLATFORM:
        sources += ['platform/renderer_web.cpp']
    else:
        sources += ['platform/renderer_common.cpp']

    # remove the font render plugins
    sources = [x for x in sources if not str(x).endswith('font_renderer_default.cpp')]
    #sources = [x for x in sources if not str(x).endswith('font_renderer_raqm.cpp')]

    bld.stlib(features        = 'cxx ddf',
              includes        = ['.', '../build/proto'],
              proto_gen_py    = True,
              protoc_includes = '../proto',
              source          = sources,
              target          = 'render')

    bld.stlib(features        = 'cxx ddf',
              includes        = ['.', '../build/proto'],
              proto_gen_py    = True,
              protoc_includes = '../proto',
              source          = ['render/font/default/font_default_vertex.cpp'],
              target          = 'render_font_default')

    dmsdk_add_files(bld, '${PREFIX}/sdk/include/dmsdk', 'dmsdk')

    bld.install_files('${PREFIX}/include/render/font', 'render/font/fontmap.h')
    bld.install_files('${PREFIX}/include/render/font', 'render/font/font_glyphbank.h')
    bld.install_files('${PREFIX}/include/render/font', 'render/font/font_renderer.h')
    bld.install_files('${PREFIX}/include/render', 'render/display_profiles.h')
    bld.install_files('${PREFIX}/include/render', 'render/render.h')

    bld.install_files('${PREFIX}/lib/python', 'waf_render.py')

    bld.install_files('${PREFIX}/share/proto/render', '../proto/render/material_ddf.proto')
    bld.install_files('${PREFIX}/share/proto/render', '../proto/render/render_ddf.proto')
    bld.install_files('${PREFIX}/share/proto/render', '../proto/render/font_ddf.proto')

    if 'web' in bld.env.PLATFORM:
        bld.install_files('${PREFIX}/lib/%s/js' % bld.env['PLATFORM'], 'js/library_render.js', postpone = False)

    apidoc_extract_task(bld, [
      '../proto/render/material_ddf.proto',
      '../proto/render/render_ddf.proto',
      '../proto/render/font_ddf.proto',
      'render/render_script.cpp',
      'render/render_script_camera.cpp'])

    if not waflib.Options.options.skip_build_tests:
        bld.recurse('test')
